/*
 * Copyright (c) 2025 GuoKaiHong (Shenzhen) Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import { pasteboard } from '@kit.BasicServicesKit';
import { promptAction } from '@kit.ArkUI';

export default class AppUtil {
  static async sleep(timeout) {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(0);
      }, timeout)
    })
  }

  static uint8Array2HexStr(array: Uint8Array): string {
    let result: string = "";
    for (let i = 0; i < array.length; i++) {
      let leftHalf = (array[i] & 0xF0) >> 4;
      result += leftHalf.toString(16);
      let rightHalf = (array[i] & 0x0F);
      result += rightHalf.toString(16);
    }
    return result;
  }

  //长按复制
  // 定义方法
  static copyText(text: string) {
    // 创建剪贴板内容对象
    const pasteboardData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, text);
    // 获取系统剪贴板对象
    const systemPasteboard = pasteboard.getSystemPasteboard();
    systemPasteboard.setData(pasteboardData); // 将数据放入剪贴板
    systemPasteboard.getData().then((data) => { // 读取剪贴板内容
      if (data) {
        promptAction.showToast({
          message: '复制成功'
        });
      } else {
        promptAction.showToast({
          message: '复制失败'
        });
      }
    })

  }
}